$(function(){
	var find=$("#hide1").html();
	var userid=$("#useridhide").html();
	/*queryRole("",0,"","","","",0,find);*/
	queryRole(userid,0,"","","","",0,find);
		if(find=="0"){
			$('#usertable').bootstrapTable('hideColumn','phoneNumber');
			/*$('#usertable').bootstrapTable('hideColumn','accountid');*/
		}
});
$("#selected").click(function(){
	var rolename=$("#rolename").val();
	var method=$("select").val();
	queryRole(method,rolename);
});

function queryRole(contain,isclose,ctimestart,ctimeend,logintimestart,loginendstart,flag,find){
	$(this).hide();
	$('#usertable').bootstrapTable('destroy');
	$('#usertable').bootstrapTable({
		method: 'get',
		url: "/GameUserList/?contain="+contain+"&flag="+flag+"&isclose="+isclose+"&ctimestart="+ctimestart+"&ctimeend="+ctimeend+"&logintimestart="+logintimestart+"&loginendstart="+loginendstart+"&find="+find,
		cache: false,
		striped: true,
		pagination:true,
		pageSize:19,
		height:805,
		pageList: [5,10,15,50],
		pageNumber:1,
		sidePagination:'server',
		paginationPreText: "上一页",
		paginationNextText: "下一页",     
		paginationHAlign: "right",  
		paginationDetailHAlign: "left", 
		width:1600,
		columns: [{
			title:'全选',
			field:'select',
			checkbox:true,
			width:25,
			align:'center',
			valign:'middle'
		},{
			field: 'id',
			title: '游戏ID',
			align: 'right',
			valign: 'middle',
			formatter: turnAround,
			align: 'center'
		},{
			field: 'id',
			title: '用户标识',
			align: 'right',
			valign: 'middle',
			formatter: turnAround,
			align: 'center'
		},{
			field: 'accountid',
			title: '用户账号',
			align: 'center',
			formatter: turnAround,
			valign: 'middle'
		},{
			field: 'roleName',
			title: '昵称',
			align: 'center',
			formatter: returnValue,
			valign: 'middle'
			},{
				field: 'place',
				title: '地区',
				align: 'center',
				formatter: turnAround,
				valign: 'middle'
			},{
			field: 'integral',
			title: '身上金币',
			formatter: turnAround,
			align: 'center',
			valign: 'middle'
		},{
			field: 'bintegral',
			title: '银行金币',
			formatter: turnAround,
			align: 'center',
			valign: 'middle'
		},{
			field: 'moneyInt',
			title: '钻石数量',
			formatter: turnAround,
			align: 'center',
			valign: 'middle'
		},{
			field: 'grade',
			title: '等级',
			formatter: turnAround,
			align: 'center',
			valign: 'middle'
		},{
			field: 'exp',
			title: '经验',
			formatter: turnAround,
			align: 'center',
			valign: 'middle'
		},{
			field: 'handSome',
			title: '魅力值',
			formatter: turnAround,
			align: 'center',
			valign: 'middle'
		},{
			field: 'haveHandsome',
			title: '已兑魅力',
			formatter: turnAround,
			align: 'center',
			valign: 'middle'
		},{
			field: 'prode',
			title: '推广人',
			formatter: turnAround,
			align: 'center',
			valign: 'middle'
		},{
			field: 'admin',
			title: '管理级别',
			formatter: turnAround,
			align: 'center',
			valign: 'middle'
		},{
			field: 'regesterTime',
			title: '注册时间',
			formatter: turnAround,
			align: 'center',
			valign: 'middle'
		},{
			field: 'regesterPlace',
			title: '注册地址',
			formatter: turnAround,
			align: 'center',
			valign: 'middle'
		},{
			field: 'loginCount',
			title: '登陆次数',
			formatter: turnAround,
			align: 'center',
			valign: 'middle'
		},{
			field: 'loginTime',
			title: '最后登录时间',
			formatter: turnAround,
			align: 'center',
			valign: 'middle'
		},{
			field: 'lastLoginPlace',
			title: '最后登入地点',
			formatter: turnAround,
			align: 'center',
			valign: 'middle'
		},{
			field: 'gameState',
			title: '状态',
			align: 'center',
			valign: 'middle'
		},{
			field: 'phoneNumber',
			title: '手机号码',
			align: 'center',
			formatter: turnAround,
			valign: 'middle'
		},{
			field: 'room',
			title: '所在房间',
			formatter: turnAround,
			align: 'center',
			valign: 'middle'
		}/*,{
				field: 'operate',
				title: '操作',
				align: 'center',
				valign: 'middle',
				formatter: operateFormatter,
				events: operateEvents
			}*/]
	});
}
/**
 * table图标区
 */

function operateFormatter(value, row, index) {
	return [
		'<button class="updateUser" id="infodetail">详情</button>'
		].join('');
}
function turnAround(value, row, index){
	return decodeURI(value,"utf-8"); 
}
function returnValue(value,row,index){
	var hideSave=0;
	if($("#hide").html()=="1"){hideSave=1;}
	return "<a  onclick='openNewBlank("+row.id+","+hideSave+")'>"+value+"</a>";
}
window.operateEvents = {
		'click .updateUser': function (e, value, row, index) {
			$("#showItem").show();
			$("#shadow").show();
			$("#guserid").html(row.id);
			document.getElementById("isclose").checked=false;
			document.getElementById("upAgent").checked=false;
			$("#idnum").html("ID号码："+row.id);
			$("#originId").html("原账号："+row.id);
			$("#countNum").val(row.id);
			$("#isclose").val(1);
			$("#isclosedW").html("冻结账号");
			$("#name").val(row.roleName);
			$.get("/GetUserDetailById/?Id="+row.id,null,function(data){
				var data=JSON.parse(data);
				if(data.state==1){
					/*$("#name").val(data.data[2]);*/
					$("#sex").val(data.data[3]);
					if(data.data[15]==1){
						$("#isclosedW").html("账号解冻");
						$("#isclose").val(0);
					}else{
						$("#isclose").val(1);
						$("#isclosedW").html("冻结账号");
					}
					$("#exp").val(data.data[17]);
					$("#plantFromLoginTime").html("<p>大厅登录次数：</p>"+data.data[18]);
					$("#lastLoginTime1").html("<p>最后登录时间：</p>"+data.data[9]);
					$("#signUpTime1").html("<p>注册时间：</p>"+data.data[20]);
					$("#onlineTotalTime").html("<p>在线时长共计：</p>"+data.data[11]+"<p>游戏时长共计：</p>"+data.data[11]);
				}else{
					alert("访问数据非法");
				}
			});
		}
};
$("#turnoff").click(function(){
	$("#showItem").hide();
	$("#shadow").hide();
});
$("#save").click(function(){
	$("#showItem").hide();
	$("#shadow").hide();
	if($("#isclose").is(":checked")||$("#upAgent").is(":checked")){
		var isclose=2;
		if($("#isclose").is(":checked")){
			isclose=$("#isclose").val();
		}
		var upagent=0;
		if($("#upAgent").is(":checked")){
			upagent=1;
		}
		alert(upagent);
		var id=$("#guserid").html();
		if( isclose && upagent){
			alert(1);
			$.get("/updateGameUserIsLegitimate/",{isclose:isclose,id:id,upagent:upagent},function(data){
				var data=JSON.parse(data);
				if(data.state==1){
					alert("保存成功");
				}else{
					alert("保存失败");
				}
			});
		}
	}
});
/**
 * 图标绑定点击事件
 *//*
window.operateEvents = {
		'click .updateUser': function (e, value, row, index) {
			isModify=1;
			$("#titleId").html("修改用户");
			$(".username").val(decodeURI(row.uname,"utf-8"));
			$(".password").val(decodeURI(row.upassword,"utf-8"));
			$("#selectId").val(row.roleid);
			$("#userIds").val(row.uid);
			$("#show_div_user").show();
		}
};





 点击提交的事件  
$("#addUser").click(function(){
    $(".show_div").hide();
    var data={};
    var userName=$(".username").val();
    var chinaName=$(".password").val();
    var roleSId=$("#selectId").val();
    data.userName = userName;
    data.password = chinaName;
    data.roleSId = roleSId;
    var userid = $("#userIds").val();
    if(userid!=0 && userid!=null){
    	data.userid = userid;
    }
    if(userName && chinaName  && roleSId){
    	$(this).html('发送中...');
        $(this).css({"background":"#616161"});
        $.get("/UserAddAndUpdateWorker/",data,function(data){
        	data = decodeURI(data);
	    	var data1 = $.parseJSON(data);
	    	if(data1.state == 1){
	    		window.location.reload();
	    		alert(data1.message);
	    	}else{
	    		$(".showList_submit").html('提交');
	    		$(".showList_submit").css({"background":"#438EB9"});
	    		alert(data1.message);
	    		$("#show_div_user").show();
	    	}
        });
    }else{
        alert("填写错误");
    }
});
  */
